package demo;

import org.junit.Test;

public class Demo000002 {

    public String name;

    public float hp;

    public int damage;


    public boolean isDead() {
        return 0>=hp?true:false;
    }


    public void test2(Demo000002 h){
        h.hp-=damage;
        System.out.format("%s 正在攻击 %s, %s的血变成了 %.0f%n",name,h.name,h.name,h.hp);

        if(h.isDead())
            System.out.println(h.name +"死了！");
    }

 /*   @Test
    public  void test1(){

        final Demo000002 gareen = new Demo000002();
        gareen.name = "盖伦";
        gareen.hp = 616;
        gareen.damage = 50;

        final Demo000002 teemo = new Demo000002();
        teemo.name = "提莫";
        teemo.hp = 300;
        teemo.damage = 30;

        final Demo000002 bh = new Demo000002();
        bh.name = "赏金猎人";
        bh.hp = 500;
        bh.damage = 65;

        final Demo000002 leesin = new Demo000002();
        leesin.name = "盲僧";
        leesin.hp = 455;
        leesin.damage = 80;

        Thread t1= new Thread(){
            public void run(){
                while(!teemo.isDead()){
                    gareen.test2(teemo);
                }
            }
        };

        t1.start();

        //代码执行到这里，一直是main线程在运行
        try {
            //t1线程加入到main线程中来，只有t1线程运行结束，才会继续往下走
            t1.join();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Thread t2= new Thread(){
            public void run(){
                while(!leesin.isDead()){
                    bh.test2(leesin);
                }
            }
        };
        //会观察到盖伦把提莫杀掉后，才运行t2线程
        t2.start();

    }*/






    @Test
    public void test3(){
        final Demo000002 gareen = new Demo000002();
        gareen.name = "盖伦";
        gareen.hp = 60;
        gareen.damage = 1;

        final Demo000002 teemo = new Demo000002();
        teemo.name = "提莫";
        teemo.hp = 30;
        teemo.damage = 1;

        final Demo000002 bh = new Demo000002();
        bh.name = "赏金猎人";
        bh.hp = 50;
        bh.damage = 1;

        final Demo000002 leesin = new Demo000002();
        leesin.name = "盲僧";
        leesin.hp = 45;
        leesin.damage = 1;



        Thread t1= new Thread(){
            public void run(){
                while(!teemo.isDead()){

                    gareen.test2(teemo);
                }
            }
        };
        Thread t2= new Thread(){
            public void run(){
                while(!bh.isDead()){

                    leesin.test2(bh);
                }
            }
        };


        t1.setPriority(Thread.MAX_PRIORITY);
        t2.setPriority(Thread.MIN_PRIORITY);
        t1.start();
        t2.start();


    }

}
